#include "myCamera.h"


myCamera::myCamera(int camWidth, int camHeight, int deviceId)
{
	vidGrabber.setDeviceID(deviceId);
	vidGrabber.setDesiredFrameRate(60);
	vidGrabber.initGrabber(camWidth, camHeight);

	videoInverted.allocate(camWidth, camHeight, OF_PIXELS_RGB);
	videoTexture.allocate(videoInverted);
	ofSetVerticalSync(true);
}

myCamera::myCamera()
{
}


myCamera::~myCamera()
{
}


void myCamera:: updateFlame()
{
	vidGrabber.update();
	if (vidGrabber.isFrameNew())
	{
		ofPixels & pixels = vidGrabber.getPixels();
		for (int i = 0; i < pixels.size(); i++) {
			videoInverted[i] = 255 - pixels[i];
		}
	}
}

bool myCamera::saveFlame(string fileName)
{
	ofImage saveImage;
	ofPixels & outPixels = vidGrabber.getPixels();
	saveImage.setFromPixels(outPixels);
	saveImage.saveImage(fileName);
	return TRUE;
}